"""
行为树黑板-客户端-生命周期
"""

import py_trees


def check_foo():
    blackboard2 = py_trees.blackboard.Client(name="Reader")
    blackboard2.register_key(key="foo", access=py_trees.common.Access.READ)

    print(f"foo: {blackboard2.foo}")


def check_foo_v2():
    blackboard3 = py_trees.blackboard.Client(name="Reader", namespace="Reader")
    blackboard3.register_key(key="foo", access=py_trees.common.Access.WRITE)

    # NOTE:没有设置key的值, 运行报错
    blackboard3.foo = "bar"
    print(f"foo: {blackboard3.foo}")


if __name__ == "__main__":
    blackboard = py_trees.blackboard.Client(name="Writer")
    blackboard.register_key(key="foo", access=py_trees.common.Access.WRITE)
    blackboard.foo = "123"
    check_foo()
    check_foo_v2()

""" 
1.只有namespace 才能隔离 全局访问范围
2.Client(name="xxx") 中的name 是客户端名称, 
    依旧能够访问到全局的blackboard
3.Reader 拥有读权限
  Writer 拥有写权限
  用于划分不同客户端的访问权限
"""
